package com.atguigu.lease.web.admin.custom.converter;


import com.atguigu.lease.model.enums.ItemType;
import com.atguigu.lease.model.enums.ReleaseStatus;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

/**
 * @author:高尚
 * @data:2025/7/7 18:37
 * @description:  String --> ItemType  springmvc框架配置converter
 */
@Component //注入到IOC容器中 供配置类使用
public class StringToReleaseConverter implements Converter<String, ReleaseStatus> {
    @Override
    public ReleaseStatus convert(String source) {
        for (ReleaseStatus status : ReleaseStatus.values()) {
            if(status.getCode().equals(Integer.parseInt(source))){
                return status;
            }
        }
        throw new RuntimeException("非法参数异常，不支持"+source);
    }
}
